package org.zsk.cfl.servicetask;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * <p>
 * </p>
 *
 * @author zsk
 * @date 2020/11/17 上午10:01
 */
@Component("customServiceTask")
@Slf4j
public class CustomServiceTask implements JavaDelegate {
    @Override
    public void execute(DelegateExecution delegateExecution) {
        log.debug("自定义消息提醒服务任务-customServiceTask");
        //消息主题
        String subject = (String) Optional.ofNullable(delegateExecution.getVariable("subject")).orElseThrow(() -> new RuntimeException("消息主题为空"));
        //发送人
        String from = (String) Optional.ofNullable(delegateExecution.getVariable("from")).orElseThrow(() -> new RuntimeException("发送人为空"));
        //收件人
        String to = (String) Optional.ofNullable(delegateExecution.getVariable("to")).orElseThrow(() -> new RuntimeException("收件人为空"));
        //消息内容
        String content = (String) Optional.ofNullable(delegateExecution.getVariable("content")).orElseThrow(() -> new RuntimeException("消息内容为空"));
        log.debug("发送提醒消息： {}发送消息给{}，主题为-{}，内容为-{}", from, to, subject, content);
    }
}
